package com.zxy.controller;


import com.zxy.common.result.Result;
import com.zxy.pojo.entity.ClueTrackRecord;
import com.zxy.pojo.vo.ClueTrackRecordVo;
import com.zxy.pojo.vo.TableDataInfo;
import com.zxy.service.ClueTrackRecordService;
import com.zxy.util.OperLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clues/record")
@Slf4j
public class ClueTrackRecordController{


    @Autowired
    private ClueTrackRecordService clueTrackRecordService;

    /**
     * 获取线索跟进记录列表
     * @param clueId 线索ID
     * @return 跟进记录列表
     */
    @OperLog(title = "获取线索跟进记录列表", businessType = 0, saveParams = true)
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam("clueId") Long clueId) {
        log.info("获取线索跟进记录列表，参数: {}", clueId);
        List<ClueTrackRecord> records = clueTrackRecordService.listByClueId(clueId);
        log.info("查询到的记录数: {}, 记录内容: {}", records.size(), records);
        TableDataInfo tableDataInfo = new TableDataInfo(records, records.size());
        tableDataInfo.setCode(200);
        tableDataInfo.setMsg("查询成功");
        return tableDataInfo;
    }

    /**
     * 新增线索跟进记录
     */
    @OperLog(title = "新增线索跟进记录", businessType = 1, saveParams = true, saveResult = true)
    @PostMapping
    public Result add(@RequestBody ClueTrackRecordVo clueTrackRecordVo) {
        log.info("新增线索跟进记录: {}", clueTrackRecordVo);
        return clueTrackRecordService.add(clueTrackRecordVo);
    }
}